package com.example.zhanghehe.myapplication

import org.junit.Test

import org.junit.Assert.*
import kotlin.reflect.KProperty

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }

   class Deletegate{
       var name:String=""
       operator fun getValue(thisRef:Any?,property:KProperty<*>):String{
           val className=thisRef.toString().substringBefore('@')
           println("${className}.get invoked")
           return name
       }

       operator fun setValue(thisRef: Any?,property: KProperty<*>,value:String){
           val className=thisRef.toString().substringBefore('@')
           println("${className}.set invoked")
           name=value
       }
   }

    class MyClass1{
        var name:String by Deletegate()
    }

    class MyCLass2{
        var name:String by Deletegate()
    }



    @Test
    fun testBy() {
        var c1=MyClass1()
        var c2=MyCLass2()

        c1.name="Billy Jean"
        c2.name="Michale Jordan"
        println(c1.name)
        println(c2.name)
    }

}
